<?php
namespace plugins\com_message\controller;

use cmf\controller\ApiPluginBaseController;
use think\Db;
use think\Request;

/**
 * 
 */
class ApiIndexController extends ApiPluginBaseController
{
    private  $pageNum = "20";

    /**
     * 站内信列表页面
     */
    public function getMailList()
    {
        $data = $this->request->param();
        $where = 1;
        $sear['pagesize'] = isset( $data['pagesize'] ) ? $data [ 'pagesize' ] : $this->pageNum;
        $list = db('mail')->where($where)->paginates($sear['pagesize'] )->each(function ($item){
            $item['time'] = date('Y-m-d H:i:s',$item['time']);
            if(!empty($item['image'])){
                $item['image'] = ZY_APP_PATH.$item['image'];
            }
            $item['content'] = '';
            $item['webview'] = 'http://lk.chinawifipot.com/znhp/public/mail_content.html?id='.$item['id'];
            return $item;
        });
        return api_json_echo( true , '获取成功' , $list , 200);
    }

    /**
     *  站内信详情
     */
    public function mailInfo()
    {
        $param = $this->request->param();
        $info = db('mail')->where('id',$param['id'])->find();
        if(!empty($info['image'])){
            $info['image'] = ZY_APP_PATH.$info['image'];
        }
        if(!empty($info['content'])){
            $info['content'] = htmlspecialchars_decode($info['content']);
        }
        return api_json_echo( true , '获取成功' , $info , 200);
    }

}